/*************************************************************************
> File Name: 6.c
> Author: hzy
> Created Time: 2023-07-24 17:38:24
> Description: 6、把一个二维数组的行列互换。
************************************************************************/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

void swap(int *p)
{
    int temp, i, j;

    for (i = 0; i < 3; i++)
    {
        for (j = i+1; j < 3; j++)
        {
            temp = *(p + 3 * i + j);
            *(p + 3 * i + j) = *(p + 3 * j + i);
            *(p + 3 * j + i) = temp;
        }
    }
}

int main(int argc, char const *argv[])
{
    int a[3][3] = {1, 2, 3, 4, 5, 6, 7, 8, 9};
    int *p = &a[0][0];

    swap(p);

    for (int i = 0; i < 3; i++)
    {
        printf("\n");
        for (int j = 0; j < 3; j++)
        {
            printf("%-2d", a[i][j]);
        }
    }

    printf("\n");

    return 0;
}